#include<graphics.h>
#include<conio.h>
#include<math.h>
void main()
{
	initgraph(500, 600);
	int x[20], y[20], a = 1, b = 1;
	int k, j;
	while (1)
	{
		setcolor(YELLOW);
		setfillcolor(RED);
		for (k = 0; k < 10; k++)
		{
			x[k] = rand() % 400 + 50;
			y[k] = rand() % 400 + 50;
		}
		for (k = 0; k < 10; k++)
			fillcircle(x[k], y[k], 20);
		for (k = 0; k < 10; k++)
		{
			if (x[k] <= 20 || x[k] >= 480)a *= -1;
			if (y[k] <= 20 ||y[k] >= 580)b *= -1;
			for (j = 0; j < 10; j++)
			{
				if (k != j)
				{
					if (sqrt((x[k] - x[j])*(x[k] - x[j]) + (y[k] - y[j])*(y[k] - y[j])) <= 40)
						a *= -1;
					b *= -1;
				}
			}
			x[k] += a; y[k] += b;
			Sleep(5);
			setcolor(BLACK);
			setfillcolor(BLACK);
			fillcircle(x[k] - a, y[k] - b, 20);
		}
	}
	closegraph();
}
